<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>管理页面</title>
    <!-- 配置文件 -->
    <script type="text/javascript" src="/UEditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="/UEditor/ueditor.all.js"></script>
</head>
<body>
<ol class="breadcrumb" id="title">
    <li><a href="{:url('backend/Index/index')}">首页</a></li>
    <li><a href="{:url('backend/Article/index')}">文章管理</a></li>
    <li><a href="{:url('backend/Article/index')}">文章列表</a></li>
</ol>
    <form class="form-horizontal" id="postForm">
        <!--下拉框-->
        <input type="hidden" id="article_id" name="article_id" value="{$data.article_id ?? ''}">
        <div class="form-group">
            <label class="col-md-1 control-label">所属栏目:</label>
            <div class="col-md-3">
                <select class="form-control" name="category_id" id="category_id">
                    <option value="0">顶级栏目</option>
                    {$tree}
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-md-1 control-label">文章标题:</label>
            <div class="col-md-5">
                <input type="text" name="article_name" class="form-control" id="article_name" value="{$data.article_name ?? ''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-1 control-label">文章内容:</label>
            <div class="col-md-9">
                <script id="container" name="content" type="text/plain">{$data.content ?? ''}</script>
            </div>
        </div>
        <div class="form-grop">
            <div class="col-sm-12">
                <button id="btn" type="button" class="btn btn-success col-sm-offset-9">保存</button>
            </div>
        </div>
    </form>
<script type="text/javascript">
    var ue = UE.getEditor('container', { initialFrameHeight: 400});
        $article_id = window.location.search;
        if ($article_id.length>0) {
            $("#title").append("<li>"+"修改文章"+"</li>");
        }else {
            $("#article_id").remove();
            $("#title").append("<li>"+"新增文章"+"</li>");
        }


    $('#btn').click(function () {
        $article_id = window.location.search;
        if ($article_id.length>0) {
            $.ajax({
                url: "{:url('backend/article/update')}",
                method: "POST",
                data: $("#postForm").serialize(),
                dataType: "json",
                success: function (res) {
                    if (res.status === 0) {
                        alert(res.msg);
                        return false;
                    }
                        alert("修改成功");
                        window.location.href = "index.html";
                }
            });
        }else {
            $.ajax({
                url: "{:url('backend/article/create')}",
                method: "POST",
                data: $("#postForm").serialize(),
                dataType: "json",
                success: function (res) {
                    if (res.status === 0) {
                        alert(res.msg);
                        return false;
                    }
                    alert("新增成功");
                    window.location.href = "index.html";
                }
            });
        }
    });
</script>
</body>
</html>